package kamkor.ann.namerecog.network

import org.encog.neural.networks.BasicNetwork
import org.encog.neural.networks.layers.BasicLayer
import org.encog.neural.networks.logic.FeedforwardLogic
import org.encog.neural.data.basic.BasicNeuralData
import org.encog.neural.data.NeuralDataSet
import org.encog.neural.networks.training.propagation.back.Backpropagation
import org.encog.neural.networks.training.propagation.resilient.ResilientPropagation
import org.encog.neural.data.basic.BasicNeuralDataSet

/**
 * 
 * @author kamkor
 *
 */
class FeedforwardResilient(layers: List[BasicLayer]) extends INetwork[BasicNeuralData, Array[Double]] {	
	private val network = new BasicNetwork()	
	layers.foreach(network.addLayer(_))
	network.setLogic(new FeedforwardLogic())
	network.getStructure().finalizeStructure()
	network.reset()	
	
	//private val trainer = new Backpropagation(network, trainingSet, 0.4, 0.8)
	private var trainer = new ResilientPropagation(network, new BasicNeuralDataSet())
	
	//trainingSet: NeuralDataSet
	def compute(input: BasicNeuralData): Array[Double] = { 
		network.compute(input).getData()
	}
	
	def setTraining(trainingData: NeuralDataSet) {
		trainer = new ResilientPropagation(network, trainingData)
		trainer.setTraining(trainingData)		
	}
	
	def train() {
		trainer.iteration();
	}
	
	def getError(): Double = {
		trainer.getError()		
	}
}